#include "qmlfile.h"

#include <QtDeclarative/qdeclarative.h>
#include <QDir>
#include <QFileDialog>

QMLFile::QMLFile(QDeclarativeItem *parent):
    QDeclarativeItem(parent)
{
    // By default, QDeclarativeItem does not draw anything. If you subclass
    // QDeclarativeItem to create a visual item, you will need to uncomment the
    // following line:
    
    // setFlag(ItemHasNoContents, false);
}

QMLFile::~QMLFile()
{
}

bool QMLFile::exists(QString path)
{
    return QFile::exists(path);
}

QString QMLFile::getEntryList(QString path)
{
    QString ret;
    QDir dir(path);
    dir.setFilter(QDir::Dirs | QDir::Hidden | QDir::NoSymLinks);
    dir.setSorting(QDir::Size | QDir::Reversed);

    QFileInfoList list = dir.entryInfoList();
    for (int i = 0; i < list.size(); ++i) {
        QFileInfo fileInfo = list.at(i);
        if(i > 0){
            ret += "\\";
        }
        ret += fileInfo.fileName();
    }
    return ret;
}

QString QMLFile::getExistingDirectory(QString title, QString default_path)
{
    return QFileDialog::getExistingDirectory(NULL, title,
                                             default_path,
                                            QFileDialog::ShowDirsOnly
                                            | QFileDialog::DontResolveSymlinks);
}
